using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrow : MonoBehaviour//��ʸ
{
    private int damage;
    public float speed;//�����ٶ�
    private Rigidbody2D rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }
    public void SetDamage(int damege)
    {
        this.damage = damege;
    }
    public void PathFinding(GameObject collision)
    {
        var target = collision.transform.position;
        Vector2 direction = target - transform.position;
        rb.velocity = direction.normalized * speed;

    }
    protected void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("tower") || collision.gameObject.CompareTag("finalTarget"))//����ʿ����������tower tag������ �����ߣ�finalTarget tag�����й���
        {
            var tower = collision.gameObject.GetComponent<TowerHolder>();
            if (tower.health != 0)
            {
                tower.GetHurt(damage);
                Destroy(gameObject);
            }
        }
    }
}
